package cn.com.weshare.lock.lock;

import java.util.concurrent.TimeUnit;

/**
 * @author dujunguang
 * @description: TODO
 * @date: 2022/9/18 17:42
 **/
public class DeadLock {
    static Object lockA = new Object();
    static Object lockB = new Object();

    public static void main(String[] args) {

        new Thread(()->{
            synchronized (lockA){
                System.out.println("t1 持有了lockA \t 期望持有lockB");

                try {
                    TimeUnit.SECONDS.sleep(3);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (lockB){
                    System.out.println("t1 获取到了lockB");
                }
            }
        },"t1").start();


        new Thread(()->{
            synchronized (lockB){
                System.out.println("t1 持有了lockB \t 期望持有lockA");

                try {
                    TimeUnit.SECONDS.sleep(3);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (lockA){
                    System.out.println("t1 获取到了lockA");
                }
            }
        },"t2").start();
    }
}
